<?php

namespace app\api\controller\user;


use app\api\model\JoinType;
use app\api\services\user\JoinMerchantServices;
use app\api\validate\JoinMerchantValidate;
use app\common\controller\Api;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\Request;

/**
 * 商家入驻
 */
class JoinMerchant extends Api
{
    protected $noNeedRight = '*';

    /**
     * 商家入驻
     * @return void
     * @throws \think\Exception
     */
    public function enter()
    {
        $params = input();
        (new JoinMerchantValidate())->goCheck();
        $params['user_id'] = $this->auth->id;
        JoinMerchantServices::getInstance()->join($params);
        $this->success('提交成功');
    }

    /**
     * 回显入驻信息
     * @return void
     */
    public function getJoinMerchant()
    {
        $userid = $this->auth->id;
        $joinMerchant = JoinMerchantServices::getInstance()->getJoinMerchant($userid);
        JoinMerchantServices::decorationImgPrefixUrl($joinMerchant, ['avatar', 'business_image', 'id_card_front_image', 'id_card_back_image']);
        $this->success('获取成功', $joinMerchant);
    }

    /**
     * 入驻类型选择器
     * @return void
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public function joinTypeSelect()
    {
        $this->success(JoinType::select());
    }


}